#!/usr/bin/env python

#
# Migrate DB from hours to minutes
#
import os
import sys
sys.path.append(".")
sys.path.append("lib")

import marajo
marajo.set_env(".", None)


def migrate_db():
    """
    Migrate the Database from using Hours to using Minutes
    Anything with an "Hours" field is assumed to be the old style,
    so any minutes attached to those comments/tickets are zeroed out and replaced
    with 60*hours
    """
    from resources.comment import Comment
    cquery = Comment.find()
    cquery.filter("hours >", 0)
    for c in cquery:
        c.minutes = c.hours*60
        c.put()

    from resources.ticket import Ticket
    tquery = Ticket.find()
    tquery.filter("hours >", 0)
    for t in tquery:
        t.minutes = t.hours*60
        t.put()

if __name__ == "__main__":
    migrate_db()
